package com.neusoft.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neusoft.domain.User;
import com.neusoft.service.UserService;
import com.neusoft.service.impl.UserServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/UserController")
public class UserController {

    @Autowired
    UserService userService;

    // 检验用户手机号是否存在
    @GetMapping("/getUserById")
    public String getUserById(String userId){
            User user = userService.getUserById(userId);

            // 如果user不为空，说明该手机号已被注册
            if (user != null) {
                // 前端接收的数据是整数数据，判断 是否 == 1 说明该手机号已被注册
                return "1";
            }
            return "0";
    }

    @PostMapping("/saveUser")
    public int saveUser(User user){
            int row = userService.saveUser(user);
            return row;
    }

    @PostMapping("/getUserByIdByPass")
    public User getUserByIdByPass(User user) {
           return userService.getUserByIdByPass(user.getUserId(), user.getPassword());
    }
}
